#include "addprogram.h"
#include "ui_addprogram.h"
#include <QMessageBox>
#include "mainwindow.h"
#include <vector>
#include <QDebug>
#include "id.h"
#include "dialog.h"
#include "program.h"
#include "teacher.h"
#include "student.h"
#include "bigsave.h"
extern vector<Program*>prdata;
extern vector<Teacher*>tdata;
extern vector<student*>sdata;
extern id u;
addprogram::addprogram(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::addprogram)
{
    ui->setupUi(this);
}

addprogram::~addprogram()
{
    delete ui;
}

void addprogram::on_pushButton_2_clicked()
{
    this->close();
    Dialog*p=new(Dialog);
    p->show();
}

void addprogram::on_pushButton_clicked()
{
    QString str1=ui->lineEdit->text();
    QString str2=ui->lineEdit_2->text();
    QString str3=ui->lineEdit_3->text();
    QString str4=ui->lineEdit_4->text();
    QString str5=ui->lineEdit_5->text();
    QString str6=ui->textEdit->toPlainText();
    QString str7=ui->textEdit_2->toPlainText();
    if(str1==""||str2==""||str3==""||str4==""||str5==""||str6==""||str7==""){
        QMessageBox::information(this,"提示","请确保信息完整");
    }
    else{
        int r=0;
        for(unsigned int i=0;i<prdata.size();i++){
            if(prdata[i]->ifhave(str1)){
                r=1;
                break;
            }
        }
        if(r==1){
        QMessageBox::information(this,"提示","此项目编号已存在");
        }
        else{
    vector <QString> name;
    QStringList list=str7.split(",");
        for(int i=0;i<list.size();i++){
            name.push_back(list[i]);
     }
    unsigned int i,t;
    for(i=0;i<tdata.size();i++){
        if(tdata[i]->ifhave(u.str1))
        break;
    }
    for(t=0;t<sdata.size();t++){
        if(sdata[t]->ifhave(u.str1))
        break;
    }
    if(i!=tdata.size()){
    prdata.push_back(new Program(str1,str2,str3,tdata[i]->findname(),str4,str5,0,name,0,0,str6,3));}
    else if(t!=sdata.size()){
    prdata.push_back(new Program(str1,str2,str3,sdata[t]->findname(),str4,str5,0,name,0,0,str6,3));
    }
            QMessageBox::information(this,"提示","申请成功，请等待审核");
            bigsave();
    }}
}
